package com.kuanter.kuanterauto.adapter;

import java.util.List;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.kuanter.kuanterauto.R;
import com.kuanter.kuanterauto.entity.AccountInfo;

public class CardAccountListAdapter extends BaseAdapter {
	private List<AccountInfo> accountInfos;
	private Activity activity ;
	private View view ;
	private AccountInfo accountInfo;
	private TextView balance_tv;
	private TextView deadline_tv;
	private TextView customerGroupName_tv;
	
	public CardAccountListAdapter(List<AccountInfo> accountInfos,
			Activity activity) {
		this.accountInfos = accountInfos;
		this.activity = activity;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return accountInfos.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return accountInfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(null == convertView){
			view = View.inflate(activity, R.layout.card_and_account_listview_item, null);
		}else{
			view = convertView;
		}
		accountInfo = accountInfos.get(position);
		customerGroupName_tv = (TextView)view.findViewById(R.id.customerGroupName_tv);
		customerGroupName_tv.setText(accountInfo.getCustomerGroupName());
		balance_tv = (TextView)view.findViewById(R.id.balance_tv);
		if(accountInfo.getAccountTypeName().equals("次数")){
			balance_tv.setText((int)Float.parseFloat(accountInfo.getBalance())+accountInfo.getAccountTypeName());
		}else if(accountInfo.getAccountTypeName().equals("积分")){
			balance_tv.setText(accountInfo.getBalance()+accountInfo.getAccountTypeName());
		}
		deadline_tv = (TextView)view.findViewById(R.id.deadline_tv);
//		SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
//		Date date = new Date(Long.valueOf(accountInfo.getExpireTime()));
//		sdf.format(date)
		deadline_tv.setText(accountInfo.getExpireTime());
		return view;
	}

}
